package com.fyzk.activity.trend;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;

import com.fyzk.activity.lottery.shuzicai.klpk.KLPKPopupItemBean;
import com.fyzk.activity.lottery.shuzicai.klpk.KLPKPopupwindow;
import com.tyjc.lottery.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanxs11 on 2017/7/20.
 * 快乐扑克走势图
 */

public class KLPKTrendActivity extends TrendBaseActivity implements CompoundButton.OnCheckedChangeListener {

    private int[] popup_itemsId = {R.string.gp_klpk_renxuan1,
            R.string.gp_klpk_renxuan2, R.string.gp_klpk_renxuan3,
            R.string.gp_klpk_renxuan4, R.string.gp_klpk_renxuan5,
            R.string.gp_klpk_renxuan6, R.string.gp_klpk_caiduizi,
            R.string.gp_klpk_caibaozi,R.string.gp_klpk_caishunzi,
            R.string.gp_klpk_caitonghua,R.string.gp_klpk_caitonghuashun,
            R.string.gp_klpk_ren2_dan,R.string.gp_klpk_ren3_dan,
            R.string.gp_klpk_ren4_dan,R.string.gp_klpk_ren5_dan,
            R.string.gp_klpk_ren6_dan};
    private List<KLPKPopupItemBean> popup_items = new ArrayList<>();
    private KLPKPopupwindow top_popup;

    private RadioButton rb1;
    private RadioButton rb2;
    private RadioButton rb3;
    private RadioButton rb4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //顶部
        for (int i = 0; i < popup_itemsId.length; i++) {

            KLPKPopupItemBean itemBean = new KLPKPopupItemBean();
            itemBean.str1 = getString(popup_itemsId[i]);
            popup_items.add(itemBean);
        }

        top_popup = new KLPKPopupwindow(this, AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT,
                popup_items, 11);
        top_popup.setHm_PopupOnItemListener(this);

        top_popup.setCheckItem(0);
        topView.setCenterText(""
                + popup_items.get(0).str1);
    }

    @Override
    protected int getTopDownVisible() {
        return View.VISIBLE;
    }

    @Override
    protected View getChooseView() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.view_gp11x5_trend_choose, null);
        view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        rb1 = (RadioButton) view.findViewById(R.id.trend_choose_rb1);
        rb2 = (RadioButton) view.findViewById(R.id.trend_choose_rb2);
        rb3 = (RadioButton) view.findViewById(R.id.trend_choose_rb3);
        rb4 = (RadioButton) view.findViewById(R.id.trend_choose_rb4);

        rb1.setText("号码分布");
        rb2.setText("形态统计");
        rb3.setText("对子走势");
        rb4.setText("");

        rb1.setChecked(true);
        rb3.setVisibility(View.GONE);
        rb4.setVisibility(View.GONE);

        rb1.setOnCheckedChangeListener(this);
        rb2.setOnCheckedChangeListener(this);
        rb3.setOnCheckedChangeListener(this);
        rb4.setOnCheckedChangeListener(this);

        rb2.setChecked(true);

        return view;
    }

    @Override
    protected TrendBaseView getTrendView() {
        return new KLPKTrendView(getContext());
    }

    @Override
    protected String getBetCode(List<TrendBaseView.Drawinfor> infors) {
        return null;
    }

    @Override
    protected long getZhuShu(List<TrendBaseView.Drawinfor> infors) {
        return 0;
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            if (trendView.listener != null) {
                trendView.listener.onChooseClick(buttonView.getId());
            }
        }
    }

    @Override
    public void onCenterClick() {
        top_popup.showPopupWindow(topView);
    }

    @Override
    public void onItem(int position) {
        super.onItem(position);
        rb1.setChecked(true);
        topView.setCenterText("" + popup_items.get(position).str1);
        if (trendView.listener != null) {
            trendView.listener.onChangePayType(position);
        }
        rb3.setVisibility(View.GONE);
        switch (position) {
            case 0:     // 0-5:任选n
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 11:    // 11-15:任选n胆拖
            case 12:
            case 13:
            case 14:
            case 15:
                rb2.setText("形态统计");
                break;
            case 6:
                rb2.setText("形态走势");
                rb3.setVisibility(View.VISIBLE);
                break;
            case 7:
            case 8:
            case 9:
            case 10:
                rb2.setText("形态走势");
                break;
            default:
                break;
        }
    }

}
